package com.zh.webcommon.common.auditor.jpa;

import com.zh.webcommon.common.auth.LoginUserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.AuditorAware;

import java.util.Optional;


/**
 * 创建人、更新人字段自动注入
 * @author ZH
 * @date 18:43 2021/12/4
 */
@Slf4j
public class JpaCustomAuditorAware implements AuditorAware<String> {

    public JpaCustomAuditorAware(){
        log.info("[CustomAuditorAware] constructor ...");
    }

    @Override
    public Optional<String> getCurrentAuditor() {
        var user = LoginUserHolder.currentUserId();
        return Optional.of(user);
    }
}